package com.gobo.jinghuimall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.gobo.jinghuimall.product.vo.CategoryBrandRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gobo.jinghuimall.product.entity.CategoryBrandRelationEntity;
import com.gobo.jinghuimall.product.service.CategoryBrandRelationService;
import com.gobo.common.utils.PageUtils;
import com.gobo.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author guanbo
 * @email gobostart@163.com
 * @date 2021-10-17 20:26:24
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 获取分类关联的品牌
     */
    @GetMapping("/brands/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R brandsList(@RequestParam(required=true) Map<String, Object> params){
        List<CategoryBrandRelationVo> brandRelationVos = categoryBrandRelationService.queryBrandsList(params);
        return R.ok().put("data", brandRelationVos);
    }

    /**
     * 获取品牌关联的分类
     * /product/categorybrandrelation/catelog/list
     */
    @GetMapping("/catelog/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R categoryList(@RequestParam(required=true) Map<String, Object> params){
        List<CategoryBrandRelationEntity> brandRelationVos = categoryBrandRelationService.queryCategoryListBybrandId(params);
        return R.ok().put("data", brandRelationVos);
    }

    /**
     * product/categorybrandrelation/save
     * 新增品牌与分类关联关系
     * 请求参数
     * {"brandId":1,"catelogId":2}
     */
    @PostMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R categoryList(@RequestBody CategoryBrandRelationEntity categoryBrandRelationEntity){
        Boolean isSave =  categoryBrandRelationService.saveCategoryBrandRelation(categoryBrandRelationEntity);
        return isSave ? R.ok():R.error();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:categorybrandrelation:info")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.save(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:categorybrandrelation:update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrandrelation:delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
